<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>我的卡券</title>
    <link rel="stylesheet" href="__STATIC_URL__/static/mobile/css/weui.css" />
    <link rel="stylesheet" href="__STATIC_URL__/static/mobile/mycord/css/cord.css" />
    <link rel="stylesheet" href="__STATIC_URL__/static/css/dropload.css" />
</head>
<body>

<div class="container" id="container">




    <div class="harder"style="background:url(__STATIC_URL__/static/mobile/mycord/img/logo_2.png);background-size:100% 100%;">


        <!-- <div class="hfooter">
            <div class="hfr">发现新大陆</div>
            <div class="arrow"></div>
        </div>-->
    </div>

    <div class="body">
        <div class="nav bc_white">
            <div class="default" id="selected" data-id="selected">
                <a href="{:url('cardmarke/freecards',['card_id'=>$card['card_id']])}">
                    <img src="__STATIC_URL__/static/mobile/mycord/img/shang.png"class="icon"style="height:19px;padding-top:3px;"/>
                    <div class="ictext">本商户优惠券</div>
                </a>
            </div>
            <div class=" default" id="selected1" data-id="selected1">
                <a href="{:url('carduser/mecard',['card_id'=>$card['card_id']])}">
                    <img src="__STATIC_URL__/static/mobile/mycord/img/mycard.png"class="icon"/>
                    <div class="ictext">我的优惠券</div>
                </a>
            </div>
            <div class=" default red" id="selected2" data-id="selected2">
                <img src="__STATIC_URL__/static/mobile/mycord/img/quan.png"class="icon"/>
                <div class="ictext" id="id" data-id="{$user['card_id']}" data-code="{$user['code']}">未领取的优惠券</div>

            </div>
        </div>
        <div class="content">



            <div class="selected1" style="display:block" id="kind">

                <div id="kin"></div>

                <div class="clear"></div>

            </div>
            <div class="selected2" style="display:none">
                <div class="zanwu">
                    <img src="__STATIC_URL__/static/mobile/mycord/img/wu.png"class="wu"/>
                    <div>暂无优惠券，赶快来领取哦~~</div>
                </div>
            </div>
        </div>

    </div>
    <div class='cardWrap' id="Refresh">
        <img src="__STATIC_URL__/static/mobile/mycord/img/shuaxin.png"class="Refresh"/>
    </div>
</div>
<div id="loadingToast" style=" display: none;">
    <div class="weui-toast">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">卡券领取中</p>
    </div>
</div>
</body>
<script src="__STATIC_URL__/static/jquery/3.2.1/jquery.min.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="__STATIC_URL__/static/js/dropload.js"></script>
<script>

    $("#Refresh").click(function(){
        window.location.reload();
    })
</script>


<script>
    $(function(){
        var counter = 0;
        // 每页展示4个
        var num = 8;
        var pageStart = 0,pageEnd = 0;
        var card_id=$("#id").attr("data-id");
        var code=$("#id").attr("data-code");
        $('#kind').dropload({
            scrollArea: window,
            loadDownFn: function (me) {
                $.ajax({
                    url: "{:url('cardget/getcardslists')}",
                    type: 'post',
                    dataType: 'json',
                    data:{
                        card_id:card_id,
                        code:code
                    },
                    success: function (data) {
                         console.log(data);
                        //加载数据
                        var data=data.data;
                        var result = '';
                        counter++;
                        pageEnd = num * counter;
                        pageStart = pageEnd - num;

                        for (var i = pageStart; i < pageEnd; i++) {

                            if (data[i].count < 1) {

                                result += '<a href="javascript:;" class="clickself weui-media-box_appmsg" data-url="" data-cardid="" data-givelogid="">\n' +
                                    '                    <div class=\'cardList\'>\n' +
                                    '\n' +
                                    '                        <div class=\'cardLi\'>\n' +
                                    '                            <div class="semi_circle"></div>\n' +
                                    '                            <div class="semi_circle1"></div>\n' +
                                    '                            <div class="cardtop">\n' +
                                    '                                <div class="top_row already">全部门店</div>\n' +
                                    '\n' +
                                    '                            </div>\n' +
                                    '                            <div class=\'cardleft\'>\n' +
                                    '                                <img src=\'\' mode=\'aspectFill\' class=\'shopLogo\'/>\n' +
                                    '                            </div>\n' +
                                    '                            <div class=\'cardRight flex\'>\n' +
                                    '                                <div class=\'cardR-top\'>\n' +
                                    '                                    <div class=\'cardR-top-left\'>\n' +
                                    '                                        <div class=\'shopName\'></div>\n' +
                                    '                                        <div class=\'cardName\'></div>\n' +
                                    '                                        <div class=\'cardAddress\'></div>\n' +
                                    '                                    </div>\n' +
                                    '                                    <div class=\'cardR-top-right\'>\n' +
                                    '\n' +
                                    '                                        <!--<div class=\'cardAddress \'style="margin-top:39%;">最近距离100km</div>-->\n' +
                                    '                                    </div>\n' +
                                    '                                </div>\n' +
                                    '                                <div class=\'cardR-bottom\'>\n' +
                                    '                                    <div class=\'cardR-bottom-left\'>\n' +
                                    '                                        <div class=\'overdue\'></div>\n' +
                                    '                                        <!--<div class=\'cardAddress orange\'>剩余263天</div>-->\n' +
                                    '                                    </div>\n' +
                                    '\n' +
                                    '                                </div>\n' +
                                    '                            </div>\n' +
                                    '                        </div>\n' +
                                    '                    </div>\n' +
                                    '                </a>';
                                if((i + 1) >= data.length){
                                    // 锁定
                                    me.lock();
                                    // 无数据
                                    me.noData();
                                    break;
                                }

                            } else {
                                url="{:url('cardget/getaddcard')}";
                                console.log(11);
                                result += '<a href="javascript:;" class="clickself weui-media-box_appmsg" data-url=" '+ url +'" data-cardid="'+data[i].zs_card_id+'" data-givelogid="'+data[i].id+'">\n' +
                                    '                    <div class="cardList">\n' +
                                    '                        <div class="cardLi">\n' +
                                    '                            <div class="semi_circle"></div>\n' +
                                    '                            <div class="semi_circle1"></div>\n' +
                                    '                            <div class="cardtop">\n' +
                                    '                                <div class="top_row already">全部门店</div>\n' +
                                    '                            </div>\n' +
                                    '                            <div class="cardleft">\n' +
                                    '                                <img src="'+data[i].card_type.logo_url+'" mode="aspectFill" class="shopLogo"/>\n' +
                                    '                            </div>\n' +
                                    '                            <div class="cardRight flex">\n' +
                                    '                                <div class="cardR-top">\n' +
                                    '                                    <div class="cardR-top-left">\n' +
                                    '                                        <div class="shopName">'+data[i].card_type.title+'</div>\n' +
                                    '                                        <div class="cardName">'+data[i].card_type.brand_name+'</div>\n' +
                                    '                                        <div class="cardAddress">'+data[i].card_type.logo_url+'</div>\n' +
                                    '                                    </div>\n' +
                                    '                                    <div class="cardR-top-right">\n' +
                                    '\n' +
                                    '                                        <!--<div class=\'cardAddress \'style="margin-top:39%;">最近距离100km</div>-->\n' +
                                    '                                    </div>\n' +
                                    '                                </div>\n' +
                                    '                                <div class="cardR-bottom">\n' +
                                    '                                    <div class="cardR-bottom-left">\n' +
                                    '                                        <div class="overdue">'+data[i].card_type.brand_name+'</div>\n' +
                                    '                                        <!--<div class=\'cardAddress orange\'>剩余263天</div>-->\n' +
                                    '                                    </div>\n' +
                                    '\n' +
                                    '                                </div>\n' +
                                    '                            </div>\n' +
                                    '                        </div>\n' +
                                    '                    </div>\n' +
                                    '                </a>';
                                if((i + 1) >= data.length){
                                    // 锁定
                                    me.lock();
                                    // 无数据
                                    me.noData();
                                    break;
                                }

                            }
                        }
                        setTimeout(function(){
                            $('#kin').append(result);
                            // 每次数据加载完，必须重置
                            me.resetload();
                        },500);

                    },
                    error: function(xhr, type){
                        console.log(xhr, type);
                        // 即使加载出错，也得重置
                        me.resetload();
                    }

                })
            }
        })




    })

</script>

<script type="text/javascript">
    $(function () {
//        console.log(window.location.pathname/window.location.protocol/window.location.host);
        $('#kin').on('click', '.clickself', function() {
            var $loadingToast = $('#loadingToast');

                if ($loadingToast.css('display') != 'none') return;

                $loadingToast.fadeIn(100);
                setTimeout(function () {
                    $loadingToast.fadeOut(100);
                }, 2000);

            console.log(132);
            var url = $(this).attr("data-url");
            var cardid = $(this).attr("data-cardid");
            var givelogid = $(this).attr('data-givelogid');
            console.log(url);
            $.post({
                url: url,
                data: {
                    card_id: cardid,
                    givelogid: givelogid,
                    url: window.location.href
                },
                success: function (data) {
                    console.log(data);
//                    return;
                    wx.config({
                        debug: false,
                        appId: data.jssdk.appId,
                        timestamp: data.jssdk.timestamp,
                        nonceStr: data.jssdk.nonceStr,
                        signature: data.jssdk.signature,
                        jsApiList: [
                            'addCard'
                        ]
                    });
                    wx.ready(function () {
                        wx.addCard({
                            cardList: [
                                {
                                    cardId: cardid,
                                    cardExt: data.card.ext
                                }
                            ],
                            success: function (res) {
                                window.location.replace("{:url('cardget/cardgetsuccess')}")
                            },
                        });
                    });
                }
            })
        })
    });
</script>

</html>
